<!DOCTYPE html>
<html>
<head>
<base href="${basePath}">
<meta charset="UTF-8">
<title>创建任务</title> 

<style type="text/css">
	.selectpicker {
		display: inline-block !impotant;
	}
</style>
</head>
<body>
	$!{include("import_js_css.html")}
	$!{include("header.html")}
	<div class="menu_all">
		<div class="div_search_result clear">
			<div class="panel-heading panel-result-title">
				<h3 class="panel-title">创建任务</h3>
			</div>
			<div class="panel-form-add">
				<form class="form-horizontal" role="form" action="yueyogaAdmin/addTask.jhtml" method="POST" onsubmit="return pdSubmit()">
					<div class="panel-form-layout">
						<label for="txtTaskName" class="col-sm-1 control-label">任务名称</label>
						<div class="col-sm-3">
							<input type="text" class="form-control" name="name" id="txtTaskName" value="">
						</div>
						<label for="selStatus" class="col-sm-1 control-label">工作安排</label>
						<div class="col-sm-3">
							<select class="selectpicker show-tick" data-width="100%" name="subStatusId" id="selStatus">
								<option value=""> </option>
								<!--#for(Status s: taskTypes)-->
								<option value="${s.id}">${s.name}</option>
								<!-- #end -->
							</select>
						</div>
						<br> <br> <label for="txtExpirydate" class="col-sm-1 control-label">到期时间</label>
						<div class="col-sm-3">
							<div class="input-group date" id="txtExpirydate" data-date-format="YYYY-MM-DD">
								<input id="expirydateInput" name="expirydate" required type="text" class="form-control" />
								<span class="input-group-addon"><span class="glyphicon glyphicon-time"></span></span>
							</div>
						</div>
						<label for="selPerson" class="col-sm-1 control-label">负责人</label>
						<div class="col-sm-3">
							<select class="selectpicker show-tick" data-live-search="true" data-width="100%" name="resporId" id="selPerson">
								<option value=""> </option>
								<!--#for(GroupUserModel u: responsibles)-->
								<option value="${u.id}">${u.name}</option>
								<!-- #end -->
							</select>
						</div>
						<br /> <br /> <label for="selTaskType" class="col-sm-1 control-label">任务类别</label>
						<div class="col-sm-3">
							<select class="selectpicker show-menu-arrow" data-width="100%" required name="type" id="selTaskType">
								<option value="1">会员</option>
								<option value="2">组</option>
							</select>
						</div>
						<div id="ta_mbr_div">
							<label for="selTaskMember" class="col-sm-1 control-label">会员</label>
							<div class="col-sm-3">
								<select class="selectpicker show-tick" data-width="100%" data-live-search="true" name="memberId" id="selTaskMember">
									<option value=""> </option>
									<!--#for(Member m: members)-->
									<!-- #if(memberId*1 == m.memberid) -->
									<option value="${m.memberid}" selected>${m.name}</option>
									<!-- #else -->
									<option value="${m.memberid}">${m.name}</option>
									<!-- #end -->
									<!-- #end -->
								</select>
							</div>
						</div>
						<div id="ta_gps_div" style="display: none;">
							<label for="selTaskGroups" class="col-sm-1 control-label">组</label>
							<div class="col-sm-3">
								<select class="selectpicker show-tick" data-live-search="true" data-width="100%" name="gpsId" id="selTaskGroups">
									<option value=""> </option>
									<!--#for(Groups g: groups)-->
									<option value="${g.id}">${g.name}</option>
									<!-- #end -->
								</select>
							</div>
						</div>
						<br /> <br /> <label for="txtRemarks" class="col-sm-1 control-label">任务备注</label>
						<div class="col-sm-3">
							<textarea style="height:115px;" class="form-control panel-form-address" name="remarks" id="txtRemarks"></textarea>
						</div>
						<br> <br> <br> <br><br> <br><br>
						<div class="panel-btn-search">
							<button type="submit" class="btn btn-default btn-ade-default panel-mr">保存</button>
						</div>
					</div>
				</form>
			</div>
		</div>
	</div>
</body>
<script type="text/javascript">
$("#selPerson").val("${resporsId}");
function documentReady(){
		if ('${memberId}') {
			$("#ta_mbr_div").show();
		}		
		
		$("input[name^='membertype']").ready(function() {
			var taskType = $(this).val();
			if (taskType == 1) {
				$("#ta_mbr_div").hide();
				$("#ta_gps_div").show();
			} else {
				$("#ta_gps_div").hide();
				$("#ta_mbr_div").show();
			}
		});
		$("#selTaskType").change(function() {
			var taskType = $(this).val();
			if (taskType == 2) {
				$("#ta_mbr_div").hide();
				$("#ta_gps_div").show();
			} else {
				$("#ta_gps_div").hide();
				$("#ta_mbr_div").show();
			}
		});
		/* var msg = '${msg}';
		var txtTaskName = "${taskName}";
		var gongzuo = "${gongzuo}";
		var remarks = "${remarks}";
		if (msg && msg=='dqsjtx') {
			 alert("到期时间不能早于今天");
		}
		$("#txtTaskName").val(txtTaskName); 
		$("#txtRemarks").val(remarks); */
		var tddate = new Date(); // 获取今天时间
		tddate.setDate(tddate.getDate() -1); // 系统会自动转换
		$(".date").datetimepicker({
			format : "YYYY-MM-DD",
			language : "zh-CN",
			pickTime : false,
			minDate : tddate
		});
		
		//去掉下拉输入框
		$("#selStatus").select2({
			width: "100%",
			minimumResultsForSearch: -1
		});
		
		$("#selTaskType").select2({
			width: "100%",
			minimumResultsForSearch: -1
		});
	}
	
	
	function pdSubmit(){
		var selStatus = $("#expirydateInput").val();
		var selStatus = $("#expirydateInput").val();
		var pro_time = selStatus.split("-");
	    var cur_time = new Date();
	    var pn = pro_time[0];
	    var py = pro_time[1];
	    var pr = pro_time[2];
	    var cn = cur_time.getFullYear();
	    var cy = cur_time.getMonth() + 1;
	    var cr = cur_time.getDate();
	    
	    var pcn = pn < cn;
	    var pcy = (pn == cn)&&(py < cy);
	    var pcr = (pn == cn)&&(py == cy)&&(pr < cr);
	    if(pcn||pcy||pcr){
	    	alert("到期时间不能早于今天");
			return false;
		}
		
		var taskType = $("#selTaskType").val();
		if (taskType == "1") {
			var member = $("#selTaskMember").val();
			if (member == null || member.length <= 0) {
				alert("会员不能为空！");
				return false;
			}
		} else if (taskType == "2") {
			var taskGroup = $("#selTaskGroups").val();
			if (taskGroup == null || taskGroup.length <= 0) {
				alert("组不能为空！");
				return false;
			}
		} else {
			alert("任务类别不正确！");
			return false;
		}
		
		return true;
	}
</script>
</html>
